package com.usian.springbootmysql.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.usian.springbootmysql.pojo.ResuitVo;
import com.usian.springbootmysql.pojo.SearchDto;
import com.usian.springbootmysql.pojo.TbCollege;
import com.usian.springbootmysql.service.CollegeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/college")
public class CollegeController {
    @Autowired
   private   CollegeService collegeService;

    @RequestMapping("info")
    public TbCollege info (int id){
      TbCollege tbCollege=collegeService.getById(id);

        return tbCollege;
    }
    @RequestMapping("save")
    public ResuitVo save(@RequestBody TbCollege tbCollege){
        return collegeService.saveCollege(tbCollege);
//         new ResuitVo(200,"success",null);
    }
    @RequestMapping("update")
    public ResuitVo update(@RequestBody TbCollege tbCollege){
        collegeService.updateById(tbCollege);
        return  new ResuitVo(200,"更新成功",null);
    }
    @RequestMapping("delete")
    public ResuitVo delete(int id){
        collegeService.removeById(id);
        return  new ResuitVo(200,"删除成功",null);
    }
    @RequestMapping("list")
    public ResuitVo list(){
        List<TbCollege> list=collegeService.list();
        return  new ResuitVo(200,"success",list);
    }
    @RequestMapping("search")
    public ResuitVo search(int status){
        List<TbCollege> list=collegeService.search(status);
        return new ResuitVo(200,"success",list);
    }
    @RequestMapping("searchVo")
    public ResuitVo searchVo(@RequestBody TbCollege tbCollege){
        List<TbCollege> list=collegeService.searchVo(tbCollege);
        return new ResuitVo(200,"success",list);
    }

    @RequestMapping("page")
    public ResuitVo page(int page,int size){
//        List<TbCollege> list;
        IPage<TbCollege> pages=new Page<>(page,size);
        IPage<TbCollege> list=collegeService.page(pages);
        return new ResuitVo(200,"success",list);
    }
    @RequestMapping("searchPage")
    public ResuitVo searchPage(@RequestBody SearchDto searchDto){
        IPage<TbCollege> list=collegeService.searchPage(searchDto);
        return new ResuitVo(200,"success",list);
    }
}
